<?php
if (!defined('LEGAL_INNER_USE')){die('ILLEGAL USING!');}
#域名跳转
$url = 'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
$url = strtolower($url);
if (strstr($url, 'http://holishanghai.com')){
	$url = str_replace('http://holishanghai.com', 'http://www.holishanghai.com', $url);
	header( "HTTP/1.1 301 Moved Permanently" );
	header( "Location: ".$url );
	exit();
}
if (strstr($url, 'hmu137250') && !isset($_GET['InnerUsed'])){
	echo 'ILLEGAL USING!';
	exit;
}
if (strstr($url, 'holishanghai.com')){
	define('LOCAL_DEV', false);
} else {
	define('LOCAL_DEV', true);
}


@ini_set('display_errors', '1');
@ini_set('log_errors', '1');
error_reporting(E_ALL & ~E_NOTICE);

header("Content-type: text/html; charset=utf-8");

if (file_exists('includes/configure.php')) {
	include('includes/configure.php');
} else {
	echo 'CONFIGURE FILE MISSING...';
	exit;
}

if (isset($_GET['main_page']) && !empty($_GET['main_page'])){
	define('MAIN_PAGE', trim($_GET['main_page']));
} else {
	define('MAIN_PAGE', 'index');
}

$main_page_body_file = ROOT_TMP.'templates/tpl_'.MAIN_PAGE.'_default.php';
if (!file_exists($main_page_body_file)){
	echo 'TPL FILE MISSING';exit;
} else {
	session_start();
	#MYSQL
	require_once(ROOT_CLS.'/mysql.php');
	$db = new queryFactory();
	@$db -> connect(DB_SERVER, DB_SERVER_USERNAME, DB_SERVER_PASSWORD, DB_DATABASE);
	if (!($db -> db_connected === true)){
		die('DB CONFIGURE ERROR.');
	}
	#
	#载入函数文件
	$function_files = glob(ROOT_FUN.'functions_*.php');
	if (!empty($function_files)){
		foreach($function_files as $v){
			require_once($v);
		}
	}
	unset($function_files);
	#初始化
	require_once(ROOT_CLS.'/initClass.php');
	#
	#ajax
	if (
		(isset($_POST['ajax']) && $_POST['ajax'] == '1' && isset($_POST['act']) && !empty($_POST['act']) && function_exists('fun_'.$_POST['act'])) ||
		(isset($_GET['ajax']) && $_GET['ajax'] == '1' && isset($_GET['act']) && !empty($_GET['act']) && function_exists('fun_'.$_GET['act']))
	){
		try{
			$php_code = 'echo fun_'.(isset($_POST["act"])?$_POST["act"]:$_GET["act"]).'();';
			eval($php_code);
			unset($php_code);
		} catch(Exception $e){}
		exit;
	}
	#
	#header
	$categories = new categories;
	$allCates = $categories -> getCates();
	#print_r($allCates);exit;
	$catesSorted = $categories -> getAllCates();

	#如果有header文件，就先执行
	$header_file = ROOT_MOD_PAGES.'header_'.MAIN_PAGE.'.php';
	if (file_exists($header_file)){
		require_once($header_file);
	}
	unset($header_file);
	
}
